<?php

/**
 * @author Christopher Hazekamp
 * @copyright 2012
 */

class Cache extends FileManager
{
	private $folder;
	private $filelist;
	private $file;
	
	public function __construct($folder)
	{
		$this->folder = $folder;
	}
	
	public function set($file)
	{
		$this->file 	= $this->folder . '/' . $file . '.html';
		$this->filename = $file . '.html';
		if (is_dir($this->folder))
		{
			$this->filelist = parent::scan_dir($this->folder);
		}
		else
		{
			if (parent::create_dir($this->folder))
			{
				$this->filelist = parent::scan_dir($folder);
			}
			else
			{
				throw new ErrorHandler('De opgegeven map kan niet worden gevonden of gelezen');
			}
		}
	}
	
	public function is_cached()
	{
		if (is_array($this->filelist))
		{
			if (in_array($this->filename, $this->filelist))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	
	public function test()
	{
		print_r($this->filelist);
	}
	
	public function save($content)
	{
		parent::create($this->file, $content);
	}
	
	public function load()
	{
		echo parent::content($this->file);
		exit;
	}
	
	public function __destruct()
	{
		
	}
}

?>